package com.winchain.chainbill.bill.biz.discount.cmd;

import com.shell.bee.acct.transaction.po.AcctTxRec;
import com.shell.bee.base.utils.StringUtil;
import com.shell.framework.command.CallbackContext;
import com.shell.framework.command.CommandContext;
import com.shell.framework.command.ICallback;
import com.shell.framework.command.ICommand;
import com.shell.stellar.exception.UnCheckMsgException;
import com.winchain.chainbill.bill.base.po.CbDct;
import com.winchain.chainbill.bill.base.po.CbRec;
import com.winchain.chainbill.bill.base.po.CbSnd;
import com.winchain.chainbill.bill.base.service.CbSndService;
import com.winchain.chainbill.bill.biz.Bill;
import com.winchain.chainbill.bill.biz.discount.service.impl.BillDctFinQuotaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class BillDctFinQuotaCmd implements ICommand<Bill<CbDct>>, ICallback<Bill<CbDct>, AcctTxRec> {
	@Autowired
	private BillDctFinQuotaService billDctFinQuotaService;
	@Autowired
	private CbSndService cbSndService;

	public boolean callback(CallbackContext<Bill<CbDct>, AcctTxRec> context) throws Exception {
		execute(context);
		return false;
	}

	public boolean execute(CommandContext<Bill<CbDct>> context) throws Exception {
		String optType = context.getStringValue("quotaOptType");
		if (StringUtil.notEmpty(optType)) {
			String remark;
			switch (optType) {
			case "qt_blk":
				remark = "������������";
				break;
			case "qt_ubk":
				remark = "������������";
				break;
			case "qt_use":
				remark = "������������";
				break;
			case "qt_res":
				remark = "������������";
				break;
			default:
				throw new UnCheckMsgException("����������������" + optType);
			}
			CbRec rec = ((Bill) context.getSource()).getRec();
			Object snd = this.cbSndService.getBillSndById(rec.getRootId());
			CbDct dct = (CbDct) ((Bill) context.getSource()).getSource();
			this.billDctFinQuotaService.trade(rec, (CbSnd) snd, dct, optType, remark);
		}
		return false;
	}
}
